package com.wez.controller;

import com.wez.pojo.User;
import com.wez.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/user")
    public ModelAndView findUserById() {
        List<User> user = userService.findUser();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("User.jsp");
        modelAndView.addObject("user", user);
        return modelAndView;
    }

    @RequestMapping("/deleteUser")
    public String deleteUserById(Integer id) {
        userService.deleteUserById(id);
        return "redirect:/user";
    }
}